home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 April / macformat-023.iso / Shareware City / Developers / ArrowCDEF / ArrowCDEFUtils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-10  |  3.6 KB  |  96 lines  |  [TEXT/KAHL]

  1. /*******************************************************************************
  2.     FILE:        ArrowCDEFUtils.c
  3.     CREATED:    November 10, 1994
  4.     AUTHOR:        David Hay
  5.     VERSION:    1.0
  6.     
  7.     This is a collection of utilities to make working with the ArrowCDEF a
  8.     bit easier. See each function header for information about how to use
  9.     a particular function.
  10.     
  11.     Comments and suggestions and suggestions about what would be considered
  12.     useful utility routines for the ArrowCDEF are encouraged. I'm not sure
  13.     what all should or could be included so let me know what you think!
  14.     
  15.     Copyright © 1994  David Hay
  16.     
  17.     CHANGE HISTORY:
  18.         1.0        --    Initial release
  19. *******************************************************************************/
  20.  
  21. #include "ArrowCDEF.h"
  22. #include "ArrowCDEFUtils.h"
  23.  
  24. struct APICData        /* The data we get from the resource */
  25. {
  26.     short    plainPictID;    /* PICT to draw for an unhilited arrow            */
  27.     short    upPictID;        /* PICT to draw when the up arrow is pressed    */
  28.     short    downPictID;        /* PICT to draw then the down arrow is pressed    */
  29.     short    inactivePictID;    /* PICT to draw when the arrow is inactive        */
  30. };
  31.  
  32. typedef struct APICData APICData;
  33. typedef APICData *APICPtr, **APICHandle;
  34.  
  35.  
  36. /*******************************************************************************
  37.  * FUNCTION:    SetArrowAPIC
  38.  *
  39.  * INPUT:        ControlHandle arrow    -- the arrow to change the APIC resource of
  40.  *                short apicID        -- the new APIC resource number
  41.  *                Boolean redraw        -- should the control be redrawn?
  42.  * RETURNS:        Nothing.
  43.  *
  44.  * DESCRIPTION:    Changes the pictures of an arrow to the pictures defined by an
  45.  *                APIC resource given by apicID.
  46.  *******************************************************************************/
  47. void SetArrowAPIC( ControlHandle arrow, short apicID, Boolean redraw )
  48. {
  49.     APICHandle    apic;
  50.     
  51.     apic = (APICHandle) GetResource( kArrowResType, apicID );
  52.     SetArrowPictures( arrow, (**apic).plainPictID, (**apic).upPictID,
  53.                       (**apic).downPictID, (**apic).inactivePictID, redraw );
  54.     ReleaseResource( (Handle) apic );
  55. }
  56.  
  57. /*******************************************************************************
  58.  * FUNCTION:    SetArrowPictures
  59.  *
  60.  * INPUT:        ControlHandle arrow    -- the arrow to change the pictures of
  61.  *                short plainPICT        -- Pict for drawing the arrow unhilted
  62.  *                short upPICT        -- Pict for arrow with the up button pressed
  63.  *                short downPICT        -- Pict for arrow with the down button pressed
  64.  *                short inactivePICT    -- Pict for drawing the arrow as inactive
  65.  *                Boolean redraw        -- should we redraw the control?
  66.  * RETURNS:        Nothing.
  67.  *
  68.  * DESCRIPTION:    Changes the pictures of an arrow to the pictures given by the
  69.  *                individual ID numbers. If redraw is true, the control is
  70.  *                invalidated so that it gets redrawn during the next update event.
  71.  *******************************************************************************/
  72. void SetArrowPictures( ControlHandle arrow, short plainPICT, short upPICT,
  73.                        short downPICT, short inactivePICT, Boolean redraw )
  74. {
  75.     APICHandle    apic;
  76.     Rect        arrowRect;
  77.     GrafPtr        savePort;
  78.     SignedByte    hState;
  79.     
  80.     apic = (APICHandle) (**arrow).contrlData;    /* update the pict resources */
  81.     (**apic).plainPictID = plainPICT;            /* within the control's data */
  82.     (**apic).upPictID = upPICT;                    /* field with the new values */
  83.     (**apic).downPictID = downPICT;                /* passed in as parameters   */
  84.     (**apic).inactivePictID = inactivePICT;
  85.     
  86.     if ( redraw )    /* We're to redraw the control */
  87.     {
  88.         GetPort( &savePort );
  89.         hState = HGetState( (Handle) arrow );
  90.         SetPort( (**arrow).contrlOwner );
  91.         arrowRect = (**arrow).contrlRect;
  92.         InvalRect( &arrowRect );
  93.         SetPort( savePort );
  94.         HSetState( (Handle) arrow, hState );
  95.     }
  96. }